package edu.fiu.cis.personalize.server.graph.store;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import edu.fiu.cis.personalize.server.graph.Node;

public/**
 * Stores in and outlinks of a particular type, along with a double weight
 */
class Edges<E extends Node> {

	private Map<Integer, Double> inLinks = new ConcurrentHashMap<Integer, Double>();
	private Map<Integer, Double> outLinks = new ConcurrentHashMap<Integer, Double>();

	public void addInLink(Node n, double w) {
		inLinks.put(n.getId(), w);
	}

	public void addOutLink(Node n, double w) {
		outLinks.put(n.getId(), w);
	}

	public int getInDegree() {
		return getInLinkIds().size();
	}

	public int getOutDegree() {
		return getOutLinkIds().size();
	}

	public Set<Integer> getInLinkIds() {
		return inLinks.keySet();
	}

	public Set<Integer> getOutLinkIds() {
		return outLinks.keySet();
	}

	public double getOutLinkWeight(Node n) {
		return outLinks.containsKey(n.getId()) ? outLinks.get(n.getId()) : 0;
	}

	public double getInLinkWeight(Node n) {
		return inLinks.containsKey(n.getId()) ? inLinks.get(n.getId()) : 0;
	}

	public Map<Integer, Double> getInLinksMap() {
		return inLinks;
	}

	public Map<Integer, Double> getOutLinksMap() {
		return outLinks;
	}

	public static Edges<Node> load(Map<Integer, Double> inLinks2,
			Map<Integer, Double> outLinks2) {
		Edges<Node> n = new Edges<Node>();

		n.inLinks = inLinks2;
		n.outLinks = outLinks2;

		return n;
	}

	public boolean hasOutLink(int id) {
		return outLinks.containsKey(id);
	}

	public boolean hasInLink(int id) {
		return inLinks.containsKey(id);
	}

}